package com.chat.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chat.app.utils.AesCipherUtil;
import com.chat.common.model.AjaxResult;
import com.chat.entity.UserEntity;
import com.chat.video.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Reference
    private UserService userService;


    @ResponseBody
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(required=false,defaultValue = "1") int pageSize,@RequestParam(required=false,defaultValue = "2")  int pageLimit){
        IPage<UserEntity> list=userService.list(pageSize,pageLimit);
        return AjaxResult.success(list);
    }

    @ResponseBody
    @GetMapping("/listAll")
    public AjaxResult listAll(){
        List<UserEntity> list=userService.listAll();
        return AjaxResult.success(list);
    }

    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable("id") String id){
        UserEntity data=userService.info(id);
        return AjaxResult.success(data);
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody UserEntity userEntity){
        userService.update(userEntity);
        return AjaxResult.success();
    }

    @PostMapping("/save")
    public AjaxResult save(@RequestBody UserEntity userEntity){
        userService.save(userEntity);
        return AjaxResult.success();
    }

    @PostMapping("/delete")
    public AjaxResult delete(@RequestParam String ids[]){
        userService.delete(ids);
        return AjaxResult.success();
    }

    @GetMapping("/password")
    public AjaxResult password(@RequestParam String password){
        // 密码进行AES解密
        String key = AesCipherUtil.deCrypto(password);
        return AjaxResult.success(key);
    }
}
